<?php
/**
 * Enter description here ...
 * @author Micou13630
 *
 */
class Bones {
	/**
	 *
	 * Enter description here ...
	 */
	private $debugMode = false;
	private $debugColor = "red";
	
	/**
	 * Constructeur
	 */
	public function Bones() {

	}

	/**
	 * Enter description here ...
	 * @param unknown_type $name
	 * @param unknown_type $arg
	 */
	public function set($prop, $val){
		if (property_exists($this, $prop)) $this->$prop = $val;
		else MessageCollectionLog::getInstance()->addMessage(
					new MessageLog(	MessageLog::TYPE_WARN, 
									get_class($this)." - [ID:".$this->ID."]", 
									"La propriete '".$prop."' est inexistant"));
	}

	/**
	 * Permet de passer en mode developpement
	 * @param boolean $b
	 */
	public function debugMode($b, $color = "red") {
		$this->debugMode = $b;
		$this->debugColor = $color;
	}

	/**
	 * Enter description here ...
	 * @param mixed $prop
	 * @return string
	 */
	protected function getProp($obj, $str = "") {
		$listProp = get_object_vars($obj);
		$first = true;
		foreach ($listProp as $prop => $value) {
		
			if (is_string($value) && $prop === 'ID') {
				$str.= (isset($value))?($first?'':',').$prop.':"'.addcslashes($value, '"').'"':'';
			}
			elseif (is_string($value) && $prop === 'debugColor') {
				// On ne fait rien
			}
			elseif (is_string($value) && $prop === 'border' && $this->debugMode) {
				// On ne fait rien
			}
			elseif (is_bool($value) && $prop === 'debugMode') {
				if ($this->debugMode)
				$str.= (isset($value))?($first?'':',').'border:"solid 2px '.$this->debugColor.'"':'';
			}
			elseif (is_string($value)) {
				if (Config::getParams()->ENCODE_UTF8 == '1') $value = utf8_encode($value);
				$str.= (isset($value))?($first?'':',').$prop.':"'.addcslashes($value, '"').'"':'';
			}
			elseif (is_bool($value)) {
				$str.= (isset($value))?(($first?'':',').$prop.':'.($value?"true":"false")):'';
			}
			elseif (is_numeric($value)) {
				$str.= (isset($value))?($first?'':',').$prop.':'.$value:'';
			}
			elseif (is_object($value) && $value instanceof IRenderable) {
				$str.= (isset($value))?($first?'':',').$prop.':'.$value->render():'';
			}
			elseif (is_array($value) && sizeOf($value) > 0) {
				$str.= ($first?'':',').$prop.':[';
				$str_member = "";
				$b = true;
				foreach ($value as $o) {
					if (!$b) $str_member.= ",";
					if ($o instanceof IRenderable) $str_member.= $o->render();
					elseif (is_string($o)) $str_member.= '"'.$o.'"';
					$b = false;
				}
				$str.= $str_member.']';
			}
			
			if (isset($value)) {
				if (!(is_array($value) && sizeOf($value) === 0)) $first = false;
			}
		}

		return $str;
	}
}
?>
